<?php 

class dl extends show
{
    public function __construct()
    {
        date_default_timezone_set('PRC');
        include_once $_SERVER['DOCUMENT_ROOT'].'/Pmodel/dbli.class.php';
        include_once $_SERVER['DOCUMENT_ROOT'].'/Pmodel/NumForChek.class.php';
        session_start();
    }
    public function login()
    {
        
        $this->display();
    }
    
    public function logined()
    {
        $uname=htmlspecialchars($_POST['manage']);
        $pass=htmlspecialchars($_POST['pass']);
        $code=is_numeric($_POST['code'])?$_POST['code']:0;
         
        if($code!=$_SESSION['codedl']){
            // print_r($_SESSION['code']);
            die('验证码不正确');
        }
        $db=new dbli($GLOBALS['C']);
        $sql="select * from `wx_daili` where name='$uname'";
       // echo $sql;
        $umessage=$db->select($sql);
        if(!$umessage){
            die('账号不存在');
        }
        if($umessage[0]['pass']!=md5($pass)){
            die('密码不正确');
        }
        $_SESSION['udl']=$umessage[0];
        die('ok');
    }
    
    public function hcode()
    {
        $code=new NumForChek();
        $code->doimg();
        $codes=$code->getCode();
        $_SESSION['codedl']=$codes;
    }
    
    public function cuser()
    {
        isset($_SESSION['udl']['ID'])?'':header('Location: /?G=dl/login');
    }
    public function main(){
        $this->cuser();
    
        $this->display();
    }
    
    public function dlls()
    {
        $this->cuser();
        $db = new dbli($GLOBALS['C']);
        $data1 = $_GET['s1'] ? strtotime($_GET['s1']) : 0;
        $data2 = $_GET['s2'] ? strtotime($_GET['s2']) + 3600 * 24 : time();
        $t = $_GET['i'] ? $_GET['i'] : 0;
        $arr=$db->select("select * from wx_manage where dlID=$t");
        $k1=0;
        $k2=0;
        $k3=0;
        $k4=0;
        foreach ($arr as $key=>$value)
        {
    
            $sql="select sum(money) as u from user_log where status=2 and uid={$value['ID']} and (gtime between $data1 and $data2)";
            $x1=$db->select($sql);
            $arr[$key]['zj']=$x1[0]['u']?$x1[0]['u']:0;
            $k1+=$arr[$key]['zj'];
    
            $sql="select sum(money) as u from user_log where status=1 and uid={$value['ID']} and (gtime between $data1 and $data2) and dit=0";
            $x1=$db->select($sql);
            $arr[$key]['ed']=$x1[0]['u']?$x1[0]['u']:0;
            $k2+=$arr[$key]['ed'];
            
            
            $sql="select sum(money) as u from user_log where status=3 and uid={$value['ID']} and (gtime between $data1 and $data2) ";
            $x1=$db->select($sql);
            $arr[$key]['sf']=$x1[0]['u']?$x1[0]['u']:0;
            $k3+=$arr[$key]['sf'];
            
            
            $sql="select sum(money) as u from user_log where status=4 and uid={$value['ID']} and (gtime between $data1 and $data2) ";
            $x1=$db->select($sql);
            $arr[$key]['xf']=$x1[0]['u']?$x1[0]['u']:0;
            $k4+=$arr[$key]['xf'];
        }
        $array=array(
            count($arr),
            $k2,
            $k1,
            $k3,
            $k4
        );
        $this->assign('zt',$array);
        $this->assign('arr',$arr);
        $this->display();
    }
    public function dlkhxz()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $p = $_GET['p'] ? intval($_GET['p']) : 1;
        $num = 10;
        $status=$_GET['st'];
        $data1=$_GET['s1']!=0?strtotime($_GET['s1']):0;
        $data2=$_GET['s2']?strtotime($_GET['s2'].' 23:59:59'):time();
        $id=$_GET['i'];
        $sql="select a.*,b.nickname as name from user_log a ,wx_manage b where  a.uid=$id and a.uid=b.ID and (a.gtime between $data1 and $data2) ";
        $countsql = "select count(ID) as nu from user_log where (gtime between $data1 and $data2) and uid=$id ";
        if($status){$sql.="and a.status=$status ";$countsql.=" and status=$status ";}
        $sql.= ' order by a.ID desc limit ' . ($p - 1) * $num . ', ' . $num;
        $data=$db->select($sql);
        $coutdata=$db->select($countsql);
        foreach ($data as $key=>$value){$data[$key]['status']=$GLOBALS['C']['LX'][$data[$key]['status']];}
        $this->assign('arr', $data);
        $this->assign('count', $coutdata[0]['nu']);
        $this->assign('p', $p);
        $this->display();
    }
    
    
    public function updaili()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
    
        $this->assign('arr',$db->select("select * from wx_daili where ID={$_GET['i']}"));
        $this->display();
    }
    
    
    public function upxtdl()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        //$name=htmlspecialchars($_POST['name']);
        $pass=htmlspecialchars($_POST['pass']);
      
        $i=$_POST['i'];
        $sql="update wx_daili set ";
    
        if($pass){
            $sql.=" pass='".md5($pass)."'";
        }else{
            $this->assign('message',"密码不能为空！");
            $this->assign('time','3');
            $this->display('jump');
            die();
        }
        $sql.=" where ID=$i ";
//echo $sql;exit;
        if($db->U_D($sql)){
            $this->assign('message',"修改成功！");
            $this->assign('time','3');
            $this->display('jump');
        }else{
            $this->assign('message','修改失败！');
            $this->assign('time','3');
            $this->display('jump');
        }
    
    }
    
    public function dlzz()
    {
        $this->cuser();
        
        $this->display();
    }
    
    
    public function logout()
    {
        $_SESSION['udl']='';
        header('Location: /?G=dl/login');
    }
}





?>